
; PICBASIC PRO(TM) Compiler 3.0.6.4, (c) 1998, 2012 microEngineering Labs, Inc. All Rights Reserved. 
MPASMWIN_USED			EQU	1

#define	PBP_PATH	C:\PBP3\




        NOLIST
    ifdef PM_USED
        LIST
        include 'M12F615.INC'	; PM header
        XALL
        NOLIST
    else
        LIST
        LIST p = 12F615, r = dec, w = -302
        INCLUDE "P12F615.INC"	; MPASM  Header
        NOLIST
    endif
        LIST


PBP_HARDWAREDEF  macro
  endm


    ifdef PM_USED
        ;device  pic12F615, intrc_osc_noclkout, wdt_on, mclr_on, ioscfs_4mhz, protect_off
        device  pic12F615, intrc_osc_noclkout, wdt_on, mclr_off, ioscfs_4mhz, protect_off
    else
        ;__config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_ON & _IOSCFS_4MHZ & _CP_OFF
        __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _IOSCFS_4MHZ & _CP_OFF
    endif



; Define statements.
; C:\PBP3\DEVICES\PIC12F615.PBPINC	00136	DEFINE	CCP1_REG GPIO
#define		CCP1_REG		 GPIO
; C:\PBP3\DEVICES\PIC12F615.PBPINC	00137	DEFINE	CCP1_BIT 2
#define		CCP1_BIT		 2
; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\TIMERS.BAS	00017	    define INTHAND tic
#define		INTHAND		 tic
; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00024	    deFINE      OSC 4
#define		OSC		 4

RAM_START       		EQU	00040h
RAM_END         		EQU	0007Fh
RAM_BANKS       		EQU	00001h
BANK0_START     		EQU	00040h
BANK0_END       		EQU	0007Fh

; C:\PBP3\PBPPIC14.RAM     	00012	A00040	R0      VAR     WORD BANK0 SYSTEM       ' System Register
R0              		EQU	RAM_START + 000h
; C:\PBP3\PBPPIC14.RAM     	00013	A00042	R1      VAR     WORD BANK0 SYSTEM       ' System Register
R1              		EQU	RAM_START + 002h
; C:\PBP3\PBPPIC14.RAM     	00014	A00044	R2      VAR     WORD BANK0 SYSTEM       ' System Register
R2              		EQU	RAM_START + 004h
; C:\PBP3\PBPPIC14.RAM     	00015	A00046	R3      VAR     WORD BANK0 SYSTEM       ' System Register
R3              		EQU	RAM_START + 006h
; C:\PBP3\PBPPIC14.RAM     	00016	A00048	R4      VAR     WORD BANK0 SYSTEM       ' System Register
R4              		EQU	RAM_START + 008h
; C:\PBP3\PBPPIC14.RAM     	00017	A0004A	R5      VAR     WORD BANK0 SYSTEM       ' System Register
R5              		EQU	RAM_START + 00Ah
; C:\PBP3\PBPPIC14.RAM     	00018	A0004C	R6      VAR     WORD BANK0 SYSTEM       ' System Register
R6              		EQU	RAM_START + 00Ch
; C:\PBP3\PBPPIC14.RAM     	00019	A0004E	R7      VAR     WORD BANK0 SYSTEM       ' System Register
R7              		EQU	RAM_START + 00Eh
; C:\PBP3\PBPPIC14.RAM     	00020	A00050	R8      VAR     WORD BANK0 SYSTEM       ' System Register
R8              		EQU	RAM_START + 010h
; C:\PBP3\PBPPIC14.RAM     	00026	A00052	FLAGS   VAR     BYTE BANK0 SYSTEM       ' Static flags
FLAGS           		EQU	RAM_START + 012h
; C:\PBP3\PBPPIC14.RAM     	00025	A00053	GOP     VAR     BYTE BANK0 SYSTEM       ' Gen Op Parameter
GOP             		EQU	RAM_START + 013h
; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\TIMERS.BAS	00014	A00054		psave var	byte bank0 system
psave           		EQU	RAM_START + 014h
; C:\PBP3\PBPPIC14.RAM     	00022	A00055	RM1     VAR     BYTE BANK0 SYSTEM       ' Pin 1 Mask
RM1             		EQU	RAM_START + 015h
; C:\PBP3\PBPPIC14.RAM     	00024	A00056	RM2     VAR     BYTE BANK0 SYSTEM       ' Pin 2 Mask
RM2             		EQU	RAM_START + 016h
; C:\PBP3\PBPPIC14.RAM     	00021	A00057	RR1     VAR     BYTE BANK0 SYSTEM       ' Pin 1 Register
RR1             		EQU	RAM_START + 017h
; C:\PBP3\PBPPIC14.RAM     	00023	A00058	RR2     VAR     BYTE BANK0 SYSTEM       ' Pin 2 Register
RR2             		EQU	RAM_START + 018h
; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\TIMERS.BAS	00013	A00059		ssave var	byte bank0 system
ssave           		EQU	RAM_START + 019h
; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\TIMERS.BAS	00025	A0005A	    CORE_TIMER var word
_CORE_TIMER      		EQU	RAM_START + 01Ah
; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00043	A0005C	    PW          VAR WORD         ' 2nd capture value & ultimately final pulse width
_PW              		EQU	RAM_START + 01Ch
; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00042	A0005E	    T1          VAR WORD         ' 1st capture value
_T1              		EQU	RAM_START + 01Eh
; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00001	A00060	'****************************************************************
T1              		EQU	RAM_START + 020h
; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00001	A00062	'****************************************************************
PB01            		EQU	RAM_START + 022h
; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00044	A00063	    US_STATE    var byte         ' State Machine current state
_US_STATE        		EQU	RAM_START + 023h
; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\TIMERS.BAS	00012	A00070	    wsave var	byte $70 system
wsave           		EQU	RAM_START + 030h
; C:\PBP3\DEVICES\PIC12F615.PBPINC	00138	PORTL   VAR     GPIO
_PORTL           		EQU	 GPIO
; C:\PBP3\DEVICES\PIC12F615.PBPINC	00139	PORTH   VAR     GPIO
_PORTH           		EQU	 GPIO
; C:\PBP3\DEVICES\PIC12F615.PBPINC	00140	TRISL   VAR     TRISIO
_TRISL           		EQU	 TRISIO
; C:\PBP3\DEVICES\PIC12F615.PBPINC	00141	TRISH   VAR     TRISIO
_TRISH           		EQU	 TRISIO
_T1??HIGHBYTE    		EQU	_T1 + 001h
_T1??LOWBYTE     		EQU	_T1
_PW??HIGHBYTE    		EQU	_PW + 001h
_PW??LOWBYTE     		EQU	_PW
#define _TIMER0_FLAG     	_INTCON??2
#define _TIMER1_FLAG     	_PIR1??0
#define _TIMER2_FLAG     	_PIR1??1
#define _Capture         	_PIR1??5
#define _TRIGGER         	_GPIO??1
#define _SENSE           	_GPIO??2
#define _LED_GREEN       	_GPIO??5
#define _LED_RED         	_GPIO??4
#define _GND_CONT        	_GPIO??5
#define _MOTION          	_GPIO??3
#define _flag            	 PB01, 000h
#define _INTCON??2       	 INTCON, 002h
#define _PIR1??0         	 PIR1, 000h
#define _PIR1??1         	 PIR1, 001h
#define _T1CON??0        	 T1CON, 000h
#define _PIE1??1         	 PIE1, 001h
#define _PIR1??5         	 PIR1, 005h
#define _GPIO??1         	 GPIO, 001h
#define _GPIO??2         	 GPIO, 002h
#define _GPIO??5         	 GPIO, 005h
#define _GPIO??4         	 GPIO, 004h
#define _GPIO??3         	 GPIO, 003h
#define _CCP1CON??0      	 CCP1CON, 000h

; Constants.
_T2400           		EQU	00000h
_T1200           		EQU	00001h
_T9600           		EQU	00002h
_T300            		EQU	00003h
_N2400           		EQU	00004h
_N1200           		EQU	00005h
_N9600           		EQU	00006h
_N300            		EQU	00007h
_OT2400          		EQU	00008h
_OT1200          		EQU	00009h
_OT9600          		EQU	0000Ah
_OT300           		EQU	0000Bh
_ON2400          		EQU	0000Ch
_ON1200          		EQU	0000Dh
_ON9600          		EQU	0000Eh
_ON300           		EQU	0000Fh
_MSBPRE          		EQU	00000h
_LSBPRE          		EQU	00001h
_MSBPOST         		EQU	00002h
_LSBPOST         		EQU	00003h
_LSBFIRST        		EQU	00000h
_MSBFIRST        		EQU	00001h
_CLS             		EQU	00000h
_HOME            		EQU	00001h
_BELL            		EQU	00007h
_BKSP            		EQU	00008h
_TAB             		EQU	00009h
_CR              		EQU	0000Dh
_UnitOn          		EQU	00012h
_UnitOff         		EQU	0001Ah
_UnitsOff        		EQU	0001Ch
_LightsOn        		EQU	00014h
_LightsOff       		EQU	00010h
_Dim             		EQU	0001Eh
_Bright          		EQU	00016h
_TRUE            		EQU	00001h
_FALSE           		EQU	00000h
_GREEN           		EQU	00032h
_RED             		EQU	0001Eh
_S_INIT          		EQU	00000h
_S_RISE          		EQU	00001h
_S_FALL          		EQU	00002h
_S_UPDATE        		EQU	00003h
	INCLUDE	"PARKINGASSISTANT.MAC"
	INCLUDE	"C:\PBP3\PBPPIC14.LIB"


; C:\PBP3\DEVICES\PIC12F615.PBPINC	00036	#HEADER
; C:\PBP3\DEVICES\PIC12F615.PBPINC	00061	#CONFIG
; C:\PBP3\DEVICES\PIC12F615.PBPINC	00130	BANK0   $0040, $007F
; C:\PBP3\DEVICES\PIC12F615.PBPINC	00133	    #ERROR "-n option (PBPL) is not supported for this device."
; C:\PBP3\DEVICES\PIC12F615.PBPINC	00134	#ENDIF
; C:\PBP3\DEVICES\PIC12F615.PBPINC	00135	LIBRARY "PBPPIC14"
; C:\PBP3\DEVICES\PIC12F615.PBPINC	00136	DEFINE	CCP1_REG GPIO
; C:\PBP3\DEVICES\PIC12F615.PBPINC	00137	DEFINE	CCP1_BIT 2

; C:\PBP3\DEVICES\PIC12F615.PBPINC	00142	include "PBPPIC14.RAM"
; C:\PBP3\DEVICES\PIC12F615.PBPINC	00146	#HEADER

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00021	    INCLUDE "modedefs.bas"
; C:\PBP3\MODEDEFS.BAS     	00014	Symbol T2400  = 0       ' Driven True
; C:\PBP3\MODEDEFS.BAS     	00015	Symbol T1200  = 1       ' Driven True
; C:\PBP3\MODEDEFS.BAS     	00016	Symbol T9600  = 2       ' Driven True
; C:\PBP3\MODEDEFS.BAS     	00017	Symbol T300   = 3       ' Driven True
; C:\PBP3\MODEDEFS.BAS     	00019	Symbol N2400  = 4       ' Driven Inverted
; C:\PBP3\MODEDEFS.BAS     	00020	Symbol N1200  = 5       ' Driven Inverted
; C:\PBP3\MODEDEFS.BAS     	00021	Symbol N9600  = 6       ' Driven Inverted
; C:\PBP3\MODEDEFS.BAS     	00022	Symbol N300   = 7       ' Driven Inverted
; C:\PBP3\MODEDEFS.BAS     	00024	Symbol OT2400 = 8       ' Open True
; C:\PBP3\MODEDEFS.BAS     	00025	Symbol OT1200 = 9       ' Open True
; C:\PBP3\MODEDEFS.BAS     	00026	Symbol OT9600 = 10      ' Open True
; C:\PBP3\MODEDEFS.BAS     	00027	Symbol OT300  = 11      ' Open True
; C:\PBP3\MODEDEFS.BAS     	00029	Symbol ON2400 = 12      ' Open Inverted
; C:\PBP3\MODEDEFS.BAS     	00030	Symbol ON1200 = 13      ' Open Inverted
; C:\PBP3\MODEDEFS.BAS     	00031	Symbol ON9600 = 14      ' Open Inverted
; C:\PBP3\MODEDEFS.BAS     	00032	Symbol ON300  = 15      ' Open Inverted
; C:\PBP3\MODEDEFS.BAS     	00036	Symbol MSBPRE = 0       ' MSB first, sample before clock
; C:\PBP3\MODEDEFS.BAS     	00037	Symbol LSBPRE = 1       ' LSB first, sample before clock
; C:\PBP3\MODEDEFS.BAS     	00038	Symbol MSBPOST = 2      ' MSB first, sample after clock
; C:\PBP3\MODEDEFS.BAS     	00039	Symbol LSBPOST = 3      ' LSB first, sample after clock
; C:\PBP3\MODEDEFS.BAS     	00042	Symbol LSBFIRST = 0     ' LSB first
; C:\PBP3\MODEDEFS.BAS     	00043	Symbol MSBFIRST = 1     ' MSB first
; C:\PBP3\MODEDEFS.BAS     	00047	Symbol CLS = 0
; C:\PBP3\MODEDEFS.BAS     	00048	Symbol HOME = 1
; C:\PBP3\MODEDEFS.BAS     	00049	Symbol BELL = 7
; C:\PBP3\MODEDEFS.BAS     	00050	Symbol BKSP = 8
; C:\PBP3\MODEDEFS.BAS     	00051	Symbol TAB = 9
; C:\PBP3\MODEDEFS.BAS     	00052	Symbol CR = 13
; C:\PBP3\MODEDEFS.BAS     	00056	Symbol UnitOn = %10010
; C:\PBP3\MODEDEFS.BAS     	00057	Symbol UnitOff = %11010
; C:\PBP3\MODEDEFS.BAS     	00058	Symbol UnitsOff = %11100
; C:\PBP3\MODEDEFS.BAS     	00059	Symbol LightsOn = %10100
; C:\PBP3\MODEDEFS.BAS     	00060	Symbol LightsOff = %10000
; C:\PBP3\MODEDEFS.BAS     	00061	Symbol Dim = %11110
; C:\PBP3\MODEDEFS.BAS     	00062	Symbol Bright = %10110

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00022	    include "TIMERS.bas"
; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\TIMERS.BAS	00017	    define INTHAND tic
; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\TIMERS.BAS	00019	    symbol    TIMER0_FLAG =  INTCON.2
; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\TIMERS.BAS	00020	    symbol    TIMER1_FLAG =  PIR1.0
; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\TIMERS.BAS	00021	    symbol    TIMER2_FLAG =  PIR1.1
; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\TIMERS.BAS	00022	    symbol  TRUE = 1
; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\TIMERS.BAS	00023	    symbol  FALSE = 0

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\TIMERS.BAS	00027	    GOTO MAIN
	GOTO?L	_MAIN

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\TIMERS.BAS	00029	INIT_TIMER0:

	LABEL?L	_INIT_TIMER0	

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\TIMERS.BAS	00030	    OPTION_REG = %10000111     'Prep Timer0 for Counting and Self-Shutoff
	MOVE?CB	087h, OPTION_REG

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\TIMERS.BAS	00031	    TMR0 = 0
	MOVE?CB	000h, TMR0

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\TIMERS.BAS	00032	    TIMER0_FLAG = FALSE
	MOVE?CT	_FALSE, _TIMER0_FLAG

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\TIMERS.BAS	00033	    RETURN
	RETURN?	

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\TIMERS.BAS	00035	INIT_TIMER1:

	LABEL?L	_INIT_TIMER1	

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\TIMERS.BAS	00036	    T1CON = 0            ' TMR1 prescale=1, clock=Fosc/4, TMR1=off
	MOVE?CB	000h, T1CON

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\TIMERS.BAS	00037	    TMR1H = 0            ' Clear high byte of TMR1 counter
	MOVE?CB	000h, TMR1H

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\TIMERS.BAS	00038	    TMR1L = 0            ' Clear low byte
	MOVE?CB	000h, TMR1L

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\TIMERS.BAS	00039	    TIMER1_FLAG  = FALSE
	MOVE?CT	_FALSE, _TIMER1_FLAG

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\TIMERS.BAS	00040	    T1CON.0 = 1          ' Turn TMR1 on here
	MOVE?CT	001h, _T1CON??0

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\TIMERS.BAS	00041	    return
	RETURN?	

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\TIMERS.BAS	00043	INIT_TIMER2:

	LABEL?L	_INIT_TIMER2	

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\TIMERS.BAS	00044	    CORE_TIMER = 0
	MOVE?CW	000h, _CORE_TIMER

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\TIMERS.BAS	00045	    TIMER2_FLAG = FALSE  ' Start Core Timer 1ms interval
	MOVE?CT	_FALSE, _TIMER2_FLAG

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\TIMERS.BAS	00046	    PR2 = 249
	MOVE?CB	0F9h, PR2

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\TIMERS.BAS	00047	    T2CON = %00011100
	MOVE?CB	01Ch, T2CON

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\TIMERS.BAS	00048	    Return
	RETURN?	

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\TIMERS.BAS	00050	INIT_CORE_TIMER:

	LABEL?L	_INIT_CORE_TIMER	

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\TIMERS.BAS	00051	    CORE_TIMER = 0
	MOVE?CW	000h, _CORE_TIMER

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\TIMERS.BAS	00052	    TIMER2_FLAG = FALSE  ' Start Core Timer 1ms interval
	MOVE?CT	_FALSE, _TIMER2_FLAG

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\TIMERS.BAS	00053	    PR2 = 249
	MOVE?CB	0F9h, PR2

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\TIMERS.BAS	00054	    T2CON = %00011100
	MOVE?CB	01Ch, T2CON

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\TIMERS.BAS	00055	    PIE1.1 = TRUE
	MOVE?CT	_TRUE, _PIE1??1

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\TIMERS.BAS	00056	    INTCON = %11000000           ' Interrupts on
	MOVE?CB	0C0h, INTCON

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\TIMERS.BAS	00057	    Return
	RETURN?	

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\TIMERS.BAS	00060	asm

	ASM?

	; Save W, STATUS and PCLATH registers
tic 	movwf	wsave
		swapf	STATUS, W
		clrf	STATUS
		movwf	ssave
		movf	PCLATH, W
		movwf	psave

	; Insert interrupt code here
	; Save and restore FSR if used

        ;incf  _tic, F
        incfsz  _CORE_TIMER, F
        goto exit
        incf  _CORE_TIMER+1, F
exit
        bcf   PIR1, 1
	; Restore PCLATH, STATUS and W registers
		movf	psave, W
		movwf	PCLATH
		swapf	ssave, W
		movwf	STATUS
		swapf	wsave, F
		swapf	wsave, W
		retfie
	

	ENDASM?

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00024	    deFINE      OSC 4
; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00026	    GREEN       con 50  'Distance for Green Threshold
; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00027	    RED         con 30  'Distance for Red Threshold
; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00029	    S_INIT      CON 0  'State Machine
; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00030	    S_RISE      con 1  'State Machine
; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00031	    S_FALL      con 2  'State Machine
; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00032	    S_UPDATE    con 3  'State Machine
; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00034	    Symbol      Capture     = PIR1.5 ' CCP1 capture flag
; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00035	    SYMBOL      TRIGGER     = GPIO.1 ' Sonar Start Pin
; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00036	    SYMBOL      SENSE       = GPIO.2 ' Sonar Return Pin
; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00037	    SYMBOL      LED_GREEN   = GPIO.5 ' Clear LED
; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00038	    SYMBOL      LED_RED     = GPIO.4 ' Stop LED
; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00039	    SYMBOL      GND_CONT    = GPIO.5 ' Power Latch pin for shutdown
; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00040	    SYMBOL      MOTION      = GPIO.3 ' Motion Det Pin --Not needed

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00047	MAIN:  

	LABEL?L	_MAIN	

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00048	    gosub INIT_CORE_TIMER
	GOSUB?L	_INIT_CORE_TIMER

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00050	    gosub INIT_TIMER1
	GOSUB?L	_INIT_TIMER1

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00052	    US_STATE = 0
	MOVE?CB	000h, _US_STATE

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00054	    ANSEL = 0                  'Turn off Analog
	MOVE?CB	000h, ANSEL

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00055	    WPU = 0                    'Turn off Weak Pull-ups
	MOVE?CB	000h, WPU

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00056	    TRISIO = %00001100         'CCP1 input pin (Capture input on 12F615)
	MOVE?CB	00Ch, TRISIO

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00057	    GPIO = %01
	MOVE?CB	001h, GPIO

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00058	    TRIGGER = 0
	MOVE?CT	000h, _TRIGGER

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00062	    GND_CONT = 1
	MOVE?CT	001h, _GND_CONT

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00063	    flag = 0
	MOVE?CT	000h, _flag

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00065	ReLoad:

	LABEL?L	_ReLoad	

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00066	    gosub STATE_MACHINE
	GOSUB?L	_STATE_MACHINE

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00069	     if (CORE_TIMER mod 1000)  then
	MOD?WCW	_CORE_TIMER, 003E8h, T1
	CMPF?WL	T1, L00001

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00070	       if flag=0 then 
	CMPNE?TCL	_flag, 000h, L00003

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00074	            flag = 1
	MOVE?CT	001h, _flag

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00075	            toggle GPIO.5 
	TOGGLE?T	_GPIO??5

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00076	        endif
	LABEL?L	L00003	

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00077	     else
	GOTO?L	L00002
	LABEL?L	L00001	

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00078	        flag = 0
	MOVE?CT	000h, _flag

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00079	    endif  
	LABEL?L	L00002	

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00082	    GOTO ReLoad
	GOTO?L	_ReLoad

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00090	STATE_MACHINE:

	LABEL?L	_STATE_MACHINE	

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00091	    select case US_STATE

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00092	        case S_INIT
	CMPNE?BCL	_US_STATE, _S_INIT, L00007

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00093	            CCP1CON = %00000101  ' Capture mode, capture on rising edge
	MOVE?CB	005h, CCP1CON

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00094	            TRIGGER = 1          'Trigger goes High   
	MOVE?CT	001h, _TRIGGER

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00096	            TMR1H = 0            ' Clear high byte of TMR1 counter
	MOVE?CB	000h, TMR1H

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00097	            TMR1L = 0            ' Clear low byte
	MOVE?CB	000h, TMR1L

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00098	            TIMER1_FLAG  = FALSE
	MOVE?CT	_FALSE, _TIMER1_FLAG

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00099	            @ nop

	ASM?
 nop

	ENDASM?


; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00100	            @ nop

	ASM?
 nop

	ENDASM?


; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00101	            @ nop

	ASM?
 nop

	ENDASM?


; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00102	            @ nop

	ASM?
 nop

	ENDASM?


; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00103	            @ nop

	ASM?
 nop

	ENDASM?


; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00104	            Capture = 0         ' Clear capture int flag bit
	MOVE?CT	000h, _Capture

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00105	            TRIGGER = 0         'Trigger goes low and Signal is transmitted
	MOVE?CT	000h, _TRIGGER

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00106	            US_STATE = S_RISE
	MOVE?CB	_S_RISE, _US_STATE

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00107	        case S_RISE
	GOTO?L	L00006
	LABEL?L	L00007	
	CMPNE?BCL	_US_STATE, _S_RISE, L00008

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00108	            if capture then    
	CMPF?TL	_Capture, L00009

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00110	                T1.HighByte = CCPR1H
	MOVE?BB	CCPR1H, _T1??HIGHBYTE

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00111	                T1.LowByte = CCPR1L
	MOVE?BB	CCPR1L, _T1??LOWBYTE

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00113	                CCP1CON.0 = 0       ' Configure capture for falling edge now
	MOVE?CT	000h, _CCP1CON??0

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00114	                Capture = 0         ' Clear capture interrupt flag bit
	MOVE?CT	000h, _Capture

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00115	                US_STATE = S_FALL
	MOVE?CB	_S_FALL, _US_STATE

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00116	            endif
	LABEL?L	L00009	

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00117	            if  TIMER1_FLAG = TRUE then ' If Timer 1 overflowed ingnore reading
	CMPNE?TCL	_TIMER1_FLAG, _TRUE, L00011

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00118	                US_STATE = S_INIT
	MOVE?CB	_S_INIT, _US_STATE

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00119	            endif  
	LABEL?L	L00011	

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00120	        case S_FALL
	GOTO?L	L00006
	LABEL?L	L00008	
	CMPNE?BCL	_US_STATE, _S_FALL, L00013

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00121	            if capture then
	CMPF?TL	_Capture, L00014

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00123	                PW.HighByte = CCPR1H
	MOVE?BB	CCPR1H, _PW??HIGHBYTE

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00124	                PW.LowByte = CCPR1L
	MOVE?BB	CCPR1L, _PW??LOWBYTE

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00126	                PW = (PW-T1)/58           ' High pulse width = PW-T1  /58 for centimeters
	SUB?WWW	_PW, _T1, T1
	DIV?WCW	T1, 03Ah, _PW

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00127	                US_STATE = S_UPDATE
	MOVE?CB	_S_UPDATE, _US_STATE

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00128	            endif
	LABEL?L	L00014	

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00129	            if  TIMER1_FLAG = TRUE then   ' If Timer 1 overflowed ingnore reading
	CMPNE?TCL	_TIMER1_FLAG, _TRUE, L00016

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00130	                US_STATE = S_INIT
	MOVE?CB	_S_INIT, _US_STATE

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00131	            endif  
	LABEL?L	L00016	

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00132	        case S_UPDATE
	GOTO?L	L00006
	LABEL?L	L00013	
	CMPNE?BCL	_US_STATE, _S_UPDATE, L00018

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00133	            SEROUT2 0,84,[DEC PW," cm",13,10]
	SEROUT2DPIN?C	000h
	SEROUT2MODE?C	054h
	SEROUT2PACE?C	000h
	SEROUT2COUNT?C	000h
	SEROUT2NUM?W	_PW
	SEROUT2DEC?	
	SEROUT2?C	020h
	SEROUT2?C	063h
	SEROUT2?C	06Dh
	SEROUT2?C	00Dh
	SEROUT2?C	00Ah

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00134	            if PW  > GREEN   then
	CMPLE?WCL	_PW, _GREEN, L00019

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00135	                LED_GREEN = 1
	MOVE?CT	001h, _LED_GREEN

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00136	                LED_RED = 0
	MOVE?CT	000h, _LED_RED

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00137	            else
	GOTO?L	L00020
	LABEL?L	L00019	

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00138	                if PW < GREEN  then
	CMPGE?WCL	_PW, _GREEN, L00021

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00139	                    if PW > RED then 
	CMPLE?WCL	_PW, _RED, L00023

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00140	                        LED_GREEN = 1
	MOVE?CT	001h, _LED_GREEN

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00141	                        LED_RED = 1
	MOVE?CT	001h, _LED_RED

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00142	                    else
	GOTO?L	L00024
	LABEL?L	L00023	

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00143	                        LED_GREEN = 0
	MOVE?CT	000h, _LED_GREEN

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00144	                        LED_RED = 1
	MOVE?CT	001h, _LED_RED

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00145	                    endif
	LABEL?L	L00024	

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00146	                endif
	LABEL?L	L00021	

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00147	            endif
	LABEL?L	L00020	

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00148	            US_STATE = S_INIT
	MOVE?CB	_S_INIT, _US_STATE

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00149	    END SELECT
	LABEL?L	L00018	
	LABEL?L	L00006	

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00150	return
	RETURN?	

; C:\USERS\CHRISSY\PIC-BASIC-ULTRA-SONIC\PARKINGASSISTANT.PBP	00153	    END
	END?	

	END
